package org.budo.dingtalk;

import java.io.Serializable;

import com.alibaba.fastjson.JSONObject;

import lombok.Getter;
import lombok.Setter;

/**
 * @author lmw
 */
@Getter
@Setter
public class DingMessage implements Serializable {
    private static final long serialVersionUID = -7037788217323471629L;

    private String touser; // 接受者ID

    private String toparty; // 部门id列表，多个接收者用|分隔。touser或者toparty 二者有一个必填

    private String agentid; // 应用ID

    private String msgtype;

    private JSONObject body;

    public DingMessage(String msgtype, JSONObject body) {
        this.msgtype = msgtype;
        this.body = body;
    }

    public DingMessage(String agentid, String msgtype, JSONObject body) {
        this.agentid = agentid;
        this.msgtype = msgtype;
        this.body = body;
    }

    public DingMessage(String agentid, String touser, String msgtype, JSONObject body) {
        this.agentid = agentid;
        this.touser = touser;
        this.msgtype = msgtype;
        this.body = body;
    }

    public String getMessage() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msgtype", msgtype);
        jsonObject.put("touser", touser);
        jsonObject.put("toparty", toparty);
        jsonObject.put("agentid", agentid);
        jsonObject.put(msgtype, body);
        return jsonObject.toJSONString();
    }

    @Override
    public String toString() {
        return super.toString() + ", message=" + this.getMessage();
    }
}
